package com.cybertron.ironhide.search.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

public class FiltersUtil {

	public static Map<String, String> filter(Map<String, String> filters,
			String filterStr) {
		if (filters == null) {
			filters = new HashMap<String, String>();
		}
		String[] filterArr = StringUtils.split(filterStr, "__");
		if (filterArr == null || filterArr.length == 0) {
			return filters;
		}
		for (String filter : filterArr) {
			String key = StringUtils.substringBefore(filter, "--");
			String value = StringUtils.substringAfter(filter, "--");
			if (StringUtils.isBlank(key) || StringUtils.isBlank(value)) {
				continue;
			}
			filters.put(key, value);
		}
		return filters;
	}

	public static Map<String, String> filter(String filterStr) {
		return filter(null, filterStr);
	}
}
